<?php

include_once($ctx->cfgPath('lib/admin') . 'hiermenu.o.inc.php');

class cmsTplTreeView extends hiermenu {

    function generateLink($link, $id, $descr, $fullpath, $target, $nouptree) {
        $ctx = base_ApplicationContext::getInstance();
        $mediapath = $ctx->mediaPath()->main();
        $str = '';
        if ($link) {
            if (!$nouptree)
                $str .= ' ';
            $str .= $hold = '<a href="' . $link . '?dir=' . urlencode($fullpath) . '" target="' . $target . '">';
            if ($nouptree)
                $str .= '<img src="'.$mediapath.'cms/img/folder.gif" width=16 height=16 border=0 align="top">';
            if ($nouptree)
                $str .= '</a> ' . $hold;
            $str .= $descr;
            $str .= '</a>';
        } else {
            $str = " $descr";
        }
        return $str;
    }

    // wird aufgerufen, wenn unterverzeichnis offen ist
    function uptree_open($layer, $id, $descr, $dataset, $is_last, $is_first, $parent_is_last) {
        $ctx = base_ApplicationContext::getInstance();
        $mediapath = $ctx->mediaPath()->main();
        echo "<nobr>";
        $spacer = '';
        for ($i = 0; $i < $layer; $i++) {
            if ($parent_is_last[$i]) {
                $spacer .= '<img src="'.$mediapath.'0.gif" border=0 width="19" height="16" align="top">';
            } else {
                $spacer .= '<img src="'.$mediapath.'10.gif" border=0 width="19" height="16" align="top">';
            }
        }
        echo $spacer . '<a href="' . $this->script_name . '?cat=' . urlencode($dataset['fullpath']) . '">';
        if ($is_last) {
            echo '<img src="'.$mediapath.'1010.gif" border=0 width="19" height="16" align="top">';
        } else {
            echo '<img src="'.$mediapath.'101.gif" border=0 width="19" height="16" align="top">';
        }
        echo '<img src="'.$mediapath.'cms/img/folder.gif" width=16 height=16 border=0 align="top">';
        echo '</a>';
        echo $this->generateLink($this->init_data["link"], $id, $descr, $dataset['fullpath'], $this->init_data["target"], false);
        echo "</nobr><br>\n";
    }

    // wird aufgerufen, wenn unterverzeichnis geschlossen ist
    function uptree_closed($layer, $id, $descr, $dataset, $is_last, $is_first, $parent_is_last) {
        $ctx = base_ApplicationContext::getInstance();
        $mediapath = $ctx->mediaPath()->main();
        echo "<nobr>";
        $spacer = '';
        for ($i = 0; $i < $layer; $i++) {
            if ($parent_is_last[$i]) {
                $spacer .= '<img src="'.$mediapath.'0.gif" border=0 width="19" height="16" align="top">';
            } else {
                $spacer .= '<img src="'.$mediapath.'10.gif" border=0 width="19" height="16" align="top">';
            }
        }
        echo $spacer . '<a href="' . $this->script_name . '?cat=' . urlencode($dataset['fullpath']) . '">';
        if ($is_last) {
            echo '<img src="'.$mediapath.'1000.gif" border=0 width="19" height="16" align="top">';
        } else {
            echo '<img src="'.$mediapath.'100.gif" border=0 width="19" height="16" align="top">';
        }
        echo '<img src="'.$mediapath.'cms/img/folder.gif" width=16 height=16 border=0 align="top">';
        echo '</a>';
        echo $this->generateLink($this->init_data["link"], $id, $descr, $dataset['fullpath'], $this->init_data["target"], false);
        echo "</nobr><br>\n";
    }

    // wird aufgerufen, wenn kein unterverzeichnis vorhanden ist
    function nouptree($layer, $id, $descr, $dataset, $is_last, $is_first, $parent_is_last) {
        $ctx = base_ApplicationContext::getInstance();
        $mediapath = $ctx->mediaPath()->main();
        echo "<nobr>";
        $spacer = '';
        for ($i = 0; $i < $layer; $i++) {
            if ($parent_is_last[$i]) {
                $spacer .= '<img src="'.$mediapath.'0.gif" border="0" width="19" height="16" align="top">';
            } else {
                $spacer .= '<img src="'.$mediapath.'10.gif" border="0" width="19" height="16" align="top">';
            }
        }
        echo $spacer;
        if ($is_last) {
            echo '<img src="'.$mediapath.'01.gif" border="0" width="19" height="16" align="top">';
        } else {
            echo '<img src="'.$mediapath.'00.gif" border="0" width="19" height="16" align="top">';
        }
        echo $this->generateLink($this->init_data["link"], $id, $descr, $dataset['fullpath'], $this->init_data["target"], true);
        echo "</nobr><br>\n";
    }

}

?>
